package com.linkoog.devtools.intellij.ui.table.cell_editor;

import org.jetbrains.annotations.NotNull;

import javax.swing.*;

public class JTextFieldTableCellEditor extends AbstractDelegateTableCellEditor{

    public JTextFieldTableCellEditor(){
        this(new JTextField());
    }

    public JTextFieldTableCellEditor(@NotNull JTextField textField) {
        editorComponent = textField;
        this.clickCountToStart = 2;
        delegate = new EditorDelegate() {
            public void setValue(Object value) {
                textField.setText((value != null) ? value.toString().trim() : "");
            }

            public Object getCellEditorValue() {
                return textField.getText();
            }
        };
        textField.addActionListener(delegate);
    }

    @Override
    public JTextField getComponent() {
        return (JTextField) editorComponent;
    }
}
